
//
//  LHSearchCell.m
//  Project_B
//
//  Created by dllo on 15/12/30.
//  Copyright © 2015年 ZY. All rights reserved.
//

#import "LHSearchCell.h"

@implementation LHSearchCell
- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    int x = 15 * ADAPT_WIDTH;
    int y = 20 * ADAPT_HEIGHT;
    
    for (int i = 0; i < self.arr.count; i++) {
        
        self.label = [[UILabel alloc] init];
        
        float r = arc4random() % 255;
        float b = arc4random() % 255;
        float g = arc4random() % 255;
        
        self.label.textColor = [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0];
        
        LHHotSearchModel *newsSearchM = [self.arr objectAtIndex:i];
        self.label.text = newsSearchM.hotWord;
        
        CGRect w = [newsSearchM.hotWord boundingRectWithSize:CGSizeMake(SCREEN_WIDTH, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17 * ADAPT_FONT]} context:nil];
        
        self.label.frame = CGRectMake(x, y, w.size.width, 30 * ADAPT_HEIGHT);
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [tap addTarget:self action:@selector(tap:)];
        tap.numberOfTapsRequired = 1;
        tap.numberOfTouchesRequired = 1;
        [_label addGestureRecognizer:tap];
        self.label.userInteractionEnabled = YES;
        self.label.tag = 10000 + i;
        x += w.size.width + 20 * ADAPT_WIDTH;
        if (x > SCREEN_WIDTH - SCREEN_WIDTH / 2.2) {
            x = 15 * ADAPT_WIDTH;
            y += 35 * ADAPT_HEIGHT;
        }
        [self.contentView addSubview:self.label];
        
    }
    
}

-(void)tap:(UITapGestureRecognizer *)tap {
    
    UILabel *label = (UILabel *)[self.contentView viewWithTag:tap.view.tag];
    
    [self.delegate passValue:label.text];
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
